//k1编辑 2022.01.10

	//任务成功
	private _trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[0, 0, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", false];
	_trigger setTriggerTimeout [5, 5, 5, false];
	_trigger setTriggerStatements["a3e_var_Escape_MissionComplete && !a3e_var_Escape_SearchLeader_civilianReporting", "Escape_mission_end = 1; [""end2"",true,true] call BIS_fnc_endMission;", ""]; //2
	
	//任务成功（但因杀害平民而失败）
	_trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[0, 0, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", false];
	_trigger setTriggerTimeout [5, 5, 5, false];
	_trigger setTriggerStatements["a3e_var_Escape_MissionComplete && a3e_var_Escape_SearchLeader_civilianReporting", "Escape_mission_end = 1; [""end4"",true,true] call BIS_fnc_endMission;", ""];
	
	
	//任务失败（但因不是所有玩家都撤离而失败）
	_trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[0, 0, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", false];
	_trigger setTriggerTimeout [5, 5, 5, false];
	_trigger setTriggerStatements["a3e_var_Escape_MissionFailed_LeftBehind", "Escape_mission_end = 1; [""end3"",false,true] call BIS_fnc_endMission;", ""];

	//waituntil {sleep .1; !isNil "A3E_PrisonLoudspeakerObject"};
	_trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[25, 25, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", true];
	_trigger setTriggerStatements["A3E_SoundPrisonAlarm", "thisTrigger setposASL ((getposASL A3E_PrisonLoudspeakerObject) vectorAdd [0,0,4]);", ""];
	_trigger setSoundEffect ["$NONE$", "", "", "AlarmSfx"];

//玩家全部倒下
if (isServer) then {
	0 spawn {
		waitUntil {!isNil "A3E_ParamsParsed"};
		_trigger = createTrigger ["EmptyDetector", [0,0,0], false];
		_trigger setTriggerArea [0, 0, 0, false];
		_trigger setTriggerActivation ["NONE", "PRESENT", false];
		_trigger setTriggerTimeout [0, 0, 0, false];
		_trigger setTriggerStatements ["allow_FailTasks == 1 && {isMultiplayer} && {!isNil ""A3E_EscapeHasStarted""} && {count (call A3E_fnc_GetPlayers - [Player_Server] - Escape_Players_enemy) > 0} && {{(_x getVariable [""FAR_isUnconscious"",0] == 1)} count (call A3E_fnc_GetPlayers - [Player_Server] - Escape_Players_enemy) == count (call A3E_fnc_GetPlayers - [Player_Server] - Escape_Players_enemy)}", "a3e_var_Escape_AllPlayersDead = true; publicVariable ""a3e_var_Escape_AllPlayersDead""; [] spawn A3E_FNC_FailTasks;", ""]; ////
	};
};

//任务失败
0 spawn {
	waitUntil {!isNil "Escape_playerGroup"};
	_trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[0, 0, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", false];
	_trigger setTriggerTimeout [2, 2, 2, false];
	_trigger setTriggerStatements["a3e_var_Escape_AllPlayersDead || {isNull Escape_playerGroup}", "Escape_mission_end = 1; [""end1"",false,true] call BIS_fnc_endMission;", ""];
};

//创建任务
A3E_Task_Prison = player createSimpleTask ["逃出监狱"];
A3E_Task_Prison setSimpleTaskDescription [
   "你们小队正在敌人一个临时监狱里等待特种部队来接应. 当地抵抗力量把武器藏在了监狱的某处。武装自己逃出监狱!",
   "逃出监狱",
   "逃出监狱"
];
A3E_Task_Prison setTaskState "CREATED";


if (isNil "A3E_Task_Prison_Complete") then {A3E_Task_Prison_Complete = false};
if (isNil "A3E_Task_Prison_Failed") then {A3E_Task_Prison_Failed = false};

	_trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[0, 0, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", false];
	_trigger setTriggerTimeout [1, 1, 1, false];
	_trigger setTriggerStatements["A3E_Task_Prison_Complete", "A3E_Task_Prison setTaskState ""Succeeded""; if (!A3E_Task_Map_Complete) then {[""TaskAssigned"",[""In-coming"",""找到地图""]] call BIS_fnc_showNotification};", ""]; //走出50米创建找地图任务
	
	_trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[0, 0, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", false];
	_trigger setTriggerTimeout [1, 1, 1, false];
	_trigger setTriggerStatements["A3E_Task_Prison_Failed", "A3E_Task_Prison setTaskState ""Failed"";", ""];

if (isServer) then {
	_trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[0, 0, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", false];
	_trigger setTriggerTimeout [0, 0, 0, false];
	_trigger setTriggerStatements["!isNil ""A3E_EscapeHasStarted"" && {{_x distance A3E_StartPos > 50} count (call A3E_fnc_GetPlayers - [Player_Server] - Escape_Players_enemy) > 0}", "A3E_Task_Prison_Complete = true; publicVariable ""A3E_Task_Prison_Complete"";", ""];
};

// Task find Map
A3E_Task_Map = player createSimpleTask ["找到地图"];
A3E_Task_Map setSimpleTaskDescription [
   "找到敌人领土地图. 你可以在敌人巡逻队的尸体中查找地图. 并非每一个敌人都携带地图.",
   "找到地图",
   "找到地图"
];
A3E_Task_Map setTaskState "CREATED";

if (isNil "A3E_Task_Map_Complete") then {A3E_Task_Map_Complete = false};
if (isNil "A3E_Task_Map_Failed") then {A3E_Task_Map_Failed = false};

	_trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[0, 0, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", false];
	_trigger setTriggerTimeout [1, 1, 1, false];
	_trigger setTriggerStatements["A3E_Task_Map_Complete", "A3E_Task_Map setTaskState ""Succeeded""; [""TaskSucceeded"",[""Complete"",""找到地图""]] call BIS_fnc_showNotification;", ""]; //
	
	_trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[0, 0, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", false];
	_trigger setTriggerTimeout [1, 1, 1, false];
	_trigger setTriggerStatements["A3E_Task_Map_Failed", "A3E_Task_Map setTaskState ""Failed"";", ""];

A3E_Task_intel = player createSimpleTask ["找到情报"];
A3E_Task_intel setSimpleTaskDescription [
   "去敌人据点也许能找到更多线索. 情报需要拿去数据终端上传",
   "找到情报",
   "找到情报"
];
A3E_Task_intel setTaskState "CREATED";

_trigger = createTrigger["EmptyDetector", [0,0,0], false];
_trigger setTriggerArea[0, 0, 0, false];
_trigger setTriggerActivation["NONE", "PRESENT", false];
_trigger setTriggerTimeout [1, 1, 1, false];
_trigger setTriggerStatements["!isNil {A3E_Task_intel_Complete}", "A3E_Task_intel setTaskState ""Succeeded""; [""TaskSucceeded"",[""Complete"",""找到情报""]] call BIS_fnc_showNotification; if(isServer)then{0 spawn Escape_shelling_intelPos; if(isNil {Escape_intel_find})then{call Escape_create_intelMak}}", ""];


// Task Hack Commcenter
A3E_Task_ComCenter = player createSimpleTask ["入侵终端"];
A3E_Task_ComCenter setSimpleTaskDescription [
   "渗透敌方通信中心，拿手提箱靠近并攻击通信终端（通信中心中间的长方盒子），请求总部帮助撤离.",
   "入侵终端",
   "入侵终端"
];
A3E_Task_ComCenter setTaskState "CREATED";

if (isNil "A3E_Task_ComCenter_Complete") then {A3E_Task_ComCenter_Complete = false};
if (isNil "A3E_Task_ComCenter_Failed") then {A3E_Task_ComCenter_Failed = false};

	_trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[0, 0, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", false];
	_trigger setTriggerTimeout [1, 1, 1, false];
	_trigger setTriggerStatements["A3E_Task_ComCenter_Complete", "A3E_Task_ComCenter setTaskState ""Succeeded""; [""TaskSucceeded"",[""Complete"",""入侵终端""]] call BIS_fnc_showNotification;", ""];//
	
	_trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[0, 0, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", false];
	_trigger setTriggerTimeout [1, 1, 1, false];
	_trigger setTriggerStatements["A3E_Task_ComCenter_Failed", "A3E_Task_ComCenter setTaskState ""Failed"";", ""];

// Task Exfiltrate
A3E_Task_Exfil = player createSimpleTask ["撤离"];
A3E_Task_Exfil setSimpleTaskDescription [
   "在你设法联系总部之后，到达地图上标明的位置。当你确定撤离点安全时，扔一枚烟雾弹或者发射烟雾等待接送的载具到达，全员进入载具逃出敌方领土",
   "撤离",
   "撤离"
];
A3E_Task_Exfil setTaskState "CREATED";

if (isNil "A3E_Task_Exfil_Complete") then {A3E_Task_Exfil_Complete = false};
if (isNil "A3E_Task_Exfil_Failed") then {A3E_Task_Exfil_Failed = false};

	_trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[0, 0, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", false];
	_trigger setTriggerTimeout [1, 1, 1, false];
	_trigger setTriggerStatements["A3E_Task_Exfil_Complete", "A3E_Task_Exfil setTaskState ""Succeeded"";", ""];
	
	_trigger = createTrigger["EmptyDetector", [0,0,0], false];
	_trigger setTriggerArea[0, 0, 0, false];
	_trigger setTriggerActivation["NONE", "PRESENT", false];
	_trigger setTriggerTimeout [1, 1, 1, false];
	_trigger setTriggerStatements["A3E_Task_Exfil_Failed", "A3E_Task_Exfil setTaskState ""Failed"";", ""];

A3E_FNC_FailTasks = {
	if (!A3E_Task_Prison_Complete) then {A3E_Task_Prison_Failed = true};
	if (!A3E_Task_Map_Complete) then {A3E_Task_Map_Failed = true};
	if (!A3E_Task_ComCenter_Complete) then {A3E_Task_ComCenter_Failed = true};
	if (!A3E_Task_Exfil_Complete) then {A3E_Task_Exfil_Failed = true};
};

if (isNil "A3E_WorldName") then {A3E_WorldName = worldName};


player createDiaryRecord ["Diary", ["Credits", "Original Mission (Arma2) by Engima.<br />Mission ported to Arma3 by Vormulac and HyperZ.<br />Continue devlopment by NeoArmageddon.<br />Island ports and unit configs by Scruffy.<br />Additional coding and bugfixing by abelian, FrozenLiquidity, Dystopian and Phantom.<br /><br />The official co10 Escape mission for Arma3 is developed and maintained by NeoArmageddon and Scruffy."]]; 
player createDiaryRecord ["Diary", ["Hints (with spoilers)", "A local resistance member has hidden a bag of pistols in the temporary prison just before your arrival.<br /><br />
The guards will be alarmed, if you gear up or escape. Prepare for a fight!<br /><br />
The start is difficulty! Even experienced squads often fail the initial escape. Just restart and try again. I believe in you!<br /><br />
The prison is placed randomly. Search for the nearest settlement and have a look at the place-name sign.<br /><br />
Ambush enemy patrols to gear up and receive a map with the enemy POIs like ammodepots and comcenters.<br /><br />
Ambush an ammodepot to get heavy weapons like sniperrifles and launchers.<br /><br />
Ambush a comcenter and hack the com-terminal (box with green lamps). Stay near the box while hacking. An engineer hacks faster!<br /><br />
After making contact with HQ, two choppers and a gunship are dispatched to pick you up at a marked position on your map. You need to throw smoke or flare to signal the choppers you are ready for extraction.<br /><br />
Don't try to escape by boat or a captured chopper. The next island is to far away and the enemy AA is deadly for non-stealth choppers.<br /><br />
The mission is (intentionally) not easy. You probably won't make it to the choppers in the first try. Don't be upset. Try again. The mission will feel completly different every time and I garantuee you will have lots of fun even when you fail.<br /><br />
A lot of stuff is dynamic/random. Also there are plenty of customization parameters for different gameplay. You should definitly try this mission several times!<br /><br />"]];
player createDiaryRecord ["Diary", ["Mission *important*", "The guards took everything you had, weapons, maps, compasses, everything.<br /><br />If you manage to escape from the temporary prison, be sure the enemy will send what they have to try to find you.<br /><br />All enemy units have heard about your activities and capture. If you are detected by an enemy unit, the unit will contact their headquarter within seconds (so if you take action quickly, the information may never reach the headquarter).<br /><br />If your position is reported to headquarter, the search leader will focus the search in an area close to the reported position. If they lose track of you, they will assume you are still in the vicinity, and widen the search area after some amount of time.<br /><br />Altis is full of innocent civilians that are already oppressed by the occupation troops and currently not interested regarding your presence. However, if they feel threatened (that is if you kill civilians) they will turn against you and help the enemy forces by reporting in your position whenever they see you.<br /><br />To find your way home you will need to establish radio contact with your own HQ but unfortunately the enemy is jamming all communications. Only the enemies communication centers are able to establish long-range radio connections! You need to find and secure an enemy com-center and use the terminal to contact your own HQ, so they give you the coordinates of an extraction position. (Communication centers are marked on map as OPFOR flag).<br /><br />The enemy communication centers are heavily guarded. To get near a communication center you will need heavy weapons.<br /><br />The enemy has camps with heavy weapons and ammunition all over the island (marked on map as depot marker).<br /><br />To find both,the ammunition depots and communication centers, you must first find map (ambush enemy patrols and search them for their maps. Not all enemy units have a map.).<br /><br />You never die, you can only go unconscious, and your skillful teammates can fix you no matter your injuries. Some wounds can only be healed by the medic. When all of your squad are unconscious, the mission will fail.<br /><br />"]];
player createDiaryRecord ["Diary", ["Situation", "You are held prisoner in an outdoor temporary prison. Armed guards of the local milita are watching your every move while waiting for OPFOR soldiers to arrive for your questioning. Since the guards that captured you by now know too much of your intentions, you are already treated as a high priority target. At best you will be treated as a prisoner of war, but having heard of the OPFOR's interrogation methods, you suspect that the questioning will not follow conventional methods. Add the value of the intelligence you have, which will be of enormous importance for the upcoming invasion, and you surely want to keep your eyes open for a good occasion to escape. Maybe you will have your window of opportunity. Is that a backpack hidden under some moss?"]];
player createDiaryRecord ["Diary", ["Intelligence Revealed", "OPFOR and the local military seem to know about the upcoming invasion, and are working hard on defensive preparations. They have stationed ammunition depots all over Altis, as well as advanced communication centers guarded by heavy armor."]];
player createDiaryRecord ["Diary", ["Background", "Before the invasion of Altis a group of highly skilled army specialists were sent into the heart of the enemy's territory. The goal of their mission was to gather intelligence, classified as top priority information, of OPFOR defensive structures. While the mission in itself was very successful and revealed even more useful information than hoped for, the withdrawal from Altis was not. On the small and snaky roads of Altis they made one single mistake and suddenly found themselves lost. If even just for a minute, it was enough to shortly thereafter run straight into a heavily guarded road block. Without a chance to fight they were caught and taken prisoners to a temporary outdoor prison already holding an engineer thought to be killed in a helicopter crash."]];
player createDiaryRecord ["Diary", ["Global Background", "BLUFOR has secretly and for some time been planning the invasion and liberation of Altis beginning in a couple of weeks."]];
        

